Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cherow

Package Overview
Dependencies
Maintainers
2
Versions
536
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cherow

Fast and lightweight, standard-compliant javascript parser written in ECMAScript

  • 1.6.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
increased by59.04%
Maintainers
2
Weekly downloads
 
Created
Source

Cherow

NPM version Gitter chat Build status CircleCI Coverage Status

A very fast and lightweight, standards-compliant, self-hosted javascript parser with high focus on both performance and stability.

Demo and Benchmark

Features

  • Conforms to the standard ECMAScript® 2019 (ECMA-262 9th Edition) language specification (draft)
  • Support for all stage 3 proposals via option.
  • JSX support via option.
  • Experimental feature support via option.
  • Optionally track syntactic node locations
  • Modular
  • Emits an ESTree-compatible abstract syntax tree.
  • Very well tested (~46 000 unit tests with full code coverage))
  • Supports all module loaders
  • Lightweight - ~70 KB minified (18 kb smaller than Acorn)

ESNext features

Stage 3 features support. These need to be enabled with the next option.

Experimental features

Experimental features support as in NodeJS. These need to be enabled with the experimental option.

API

Cherow generates AST according to ESTree AST format, and can be used to perform syntactic analysis (parsing) of a JavaScript program, and with ES2015 and later a JavaScript program can be either a script or a module.

The parse method exposed by Cherow takes an optional options object which allows you to specify whether to parse in script mode (the default) or in module mode.

Here is a quick example to parse a script:


cherow.parseScript('x = async() => { for await (x of xs); }');

// or

cherow.parse('x = async() => { for await (x of xs); }');

This will return when serialized in json:

{
    body: [{
        expression: {
            left: {
                name: 'x',
                type: 'Identifier'
            },
            operator: '=',
            right: {
                async: true,
                body: {
                    body: [{
                        await: true,
                        body: {
                            type: 'EmptyStatement',
                        },
                        left: {
                            name: 'x',
                            type: 'Identifier',
                        },
                        right: {
                            name: 'xs',
                            type: 'Identifier',
                        },
                        type: 'ForOfStatement',
                    }],
                    type: 'BlockStatement'
                },
                expression: false,
                generator: false,
                id: null,
                params: [],
                type: 'ArrowFunctionExpression'
            },
            type: 'AssignmentExpression'
        },
        type: 'ExpressionStatement'
    }],
    sourceType: 'script',
    type: 'Program'
}

Options

The second argument allows you to specify various options:

OptionDescription
moduleEnable module syntax
locAttach line/column location information to each node
rangesAppend start and end offsets to each node
globalReturnAllow return in the global scope
skipShebangAllow to skip shebang - '#'
impliedStrictEnable strict mode initial enforcement
nextEnable stage 3 support (ESNext)
jsxEnable React JSX parsing
tolerantCreate a top-level error array containing all "skipped" errors
sourceSet to true to record the source file in every node's loc object when the loc option is set.
experimentalEnable experimental features
rawAttach raw property to each literal node
rawIdentifierAttach raw property to each identifier node
nodeAllow to bypass scoping when run in a NodejS environment

Builds

Cherow contains 3 different builds:

NameDescription
StableStable release
NextHas the next option enabled by default, and support all latest ECMAScript proposals.
BleedingThe active development branch. You can and will expect bugs with this branch because it's not stable

Contributing

If you feel something could've been done better, please do feel free to file a pull request with the changes.

Read our guidelines here

Bug reporting

If you caught a bug, don't hesitate to report it in the issue tracker. From the moment I respond to you, it will take maximum 60 minutes before the bug is fixed.

Note that I will try to respond to you within one hour. Sometimes it can take a bit longer. I'm not allways online. And if I find out it will take more then 60 minutes to solve your issue, you will be notified.

I know how irritating it can be if you are writing code and encounter bugs in your dependencies. And even more frustrating if you need to wait weeks or days.

Rationale

Existing parsers have many issues with them:

  • Acorn is the most commonly used tool out there because of its support for recent ES standards, but it's slow and it often is too permissive in what it accepts. It's also not optimized for handheld devices.

  • Esprima is a little faster than Acorn, but it's almost never updated, and their test suite has too many invalid tests. It also doesn't support recent ES standards.

  • Babylon is highly coupled to Babel, and is comparatively very slow and buggy, and failing to correctly handle even stable ECMAScript standard features.

None of these parsers would fare any chance against the official Test262 suite, and most fail a substantial number of them.

We figured we could try do better. We are used in plural form because Cherow is developed by a main developer and two others "behind the scene" that contributes with their knowledge whenever it's necessary.

Keywords

FAQs

Package last updated on 19 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc